package com.itheima.web;

import com.itheima.client.ItemClient;
import com.itheima.pojo.Result;
import com.itheima.pojo.Sku;
import com.itheima.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("search")
public class SearchController {
    @Autowired
    private SearchService searchService;
    @Autowired
    private ItemClient itemClient;
    @PostMapping("goods/init")
    public void init(){
        searchService.creatElasticsearch();
        Integer total = itemClient.getTotal();
        System.out.println(total);
        searchService.init(total);
    }
    @GetMapping("/findByKeyWord/{keyWord}")
    public Result findByKeyWord(@PathVariable("keyWord") String keyWord){
      List<Sku> skus = searchService.findByKeyWord(keyWord);
      return Result.ok(skus);
    }
}
